﻿using System;
using System.Collections.Generic;
using System.Text;
using DrugStorehouseMIS.Comm;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.DAL
{
   public  class InventoryDAL:IInventoryDAL
    {

        #region IInventoryDAL 成员

       //public static DataTable select(string drug_code, string Common_Name)
       //{
       //    try
       //    {
       //        SqlParameter[] all = new SqlParameter[]
       //         {
       //             new SqlParameter("@drug_code",drug_code),
       //             new SqlParameter("@common_name",Common_Name),
                    
       //         };
       //        return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_Inventory_Select", all);
       //    }
       //    catch (Exception ex)
       //    {
       //        EventLog.WriteErrorLog(ex.Message);
       //        throw;
       //    }
       //}

       // public int Insert(string DrugName, int StockQuantity, string BatchNum, string StockInNum, DateTime StockInDatetime, DateTime ExpiryDatetime, float TradePrice, float RetailPrice, float ImportPrice)
       // {
       //     throw new Exception("The method or operation is not implemented.");
       // }

       // public int Delete()
       // {
       //     throw new Exception("The method or operation is not implemented.");
       // }

       // public int Update(int InventoryNum, string DrugName, int StockQuantity, string BatchNum, string StockInNum, DateTime StockInDatetime, DateTime ExpiryDatetime, float TradePrice, float RetailPrice, float ImportPrice)
       // {
       //     throw new Exception("The method or operation is not implemented.");
       // }

        #endregion


        #region IInventoryDAL 成员

        public int Insert(int DrugNum, int Quantity)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@Quantity",Quantity)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_Inventory_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Add(int DrugNum, int Quantity)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@Quantity",Quantity)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_AddStock2", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

       public int Cut(int DrugNum, int Quantity)
       {
           try
           {
               SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@DrugNum",DrugNum),
                    new SqlParameter("@Quantity",Quantity)
                };
               return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_CutStock", all);
           }
           catch (Exception ex)
           {
               EventLog.WriteErrorLog(ex.Message);
               throw;
           }
       }

       public int Select(int DrugNum)
       {
           try
           {
               return (int)SqlDbHelper.RunSQL_QueryResult(ConnectionString.ConnString, "select stock_quantity from inventory where drug_num=@DrugNum", new SqlParameter[] { new SqlParameter("@DrugNum", DrugNum) });
           }
           catch (Exception ex)
           {
               EventLog.WriteErrorLog(ex.Message);
               throw;
           }
       }


        #endregion
    }
}
